import {
  CONFIG_NAMES,
  container,
  FormulaService,
  HyperFormula,
  ConfigService,
} from "./src/formula_lib";

console.log("demo");

// const configService = container.get<IConfigService>(TYPES.ConfigService);
const configService = container.get(ConfigService);
configService.set(CONFIG_NAMES.SHOW_GUI, true);
configService.set(CONFIG_NAMES.CALCULATE_STRING_DIV_ID, "myFormulaArea");

await container.start();

const formulaService: FormulaService = container.get(
  FormulaService
) as FormulaService;
(window as any).formula = formulaService;
(window as any).Hyperformula = HyperFormula;

const element = document.getElementById(
  configService.get(CONFIG_NAMES.CALCULATE_STRING_DIV_ID)
) as HTMLTextAreaElement;

element.value = "=1+1";

const str1 = "=1+1";
const str2 = "=SUM(1,2)";
const str3 = "=PMT(AnnualInterestRate/12, NumberOfMonths, -LoanAmount)";
const str4 = "=MATCH(666, {111,222,555,666,333,444})";

const testButton1 = document.createElement("button");
testButton1.textContent = str1;
testButton1.onclick = () => {
  element.value = str1;
};
document.body.appendChild(testButton1);

const testButton2 = document.createElement("button");
testButton2.textContent = str2;
testButton2.onclick = () => {
  element.value = str2;
};
document.body.appendChild(testButton2);

const testButton3 = document.createElement("button");
testButton3.textContent =
  "估算房贷月供(年利率3.3%, 贷款总额50w, 贷款期限360月)";
testButton3.onclick = () => {
  formulaService.addExpression("AnnualInterestRate", "=0.033");
  formulaService.addExpression("NumberOfMonths", "=360");
  formulaService.addExpression("LoanAmount", "=500000");
  element.value = str3;
};
document.body.appendChild(testButton3);

const testButton4 = document.createElement("button");
testButton4.textContent = "位置";
testButton4.onclick = () => {
  element.value = str4;
};
document.body.appendChild(testButton4);
